const baseConfig = require('./src/config/app')
let url = baseConfig.apiBase[process.env.NODE_ENV]  //api地址
let devServerProxy = baseConfig.proxy[baseConfig.serviceType]
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const path = require('path');
module.exports = {
  lintOnSave: true,
  productionSourceMap: false,
  // transpileDependencies: ['avue-plugin-ueditor', 'vue-echarts','resize-detector'], //解决vue-echarts不兼容ie的问题
  transpileDependencies: [ 'avue-plugin-ueditor','_vue-echarts@4.1.0@vue-echarts','vue-echarts','resize-detector','_resize-detector@0.1.10@resize-detector','_resize-detector@0.1.10@resize-detector','@sscfaith'], //解决vue-echarts不兼容ie的问题
  chainWebpack: config => {
    // 忽略的打包文件
    config.externals({
      'axios': 'axios'
    })
    config.when(process.env.NODE_ENV === 'production', config => {
      config.entry('app').clear().add('./src/entry-clientprod.js')  //生产环境
    })
    config.when(process.env.NODE_ENV === 'development', config => {
      config.entry('app').clear().add('./src/entry-client.js')     //开发环境
    })
    const entry = config.entry('app')
    entry
      .add('babel-polyfill')
      .end()
    entry
      .add('classlist-polyfill')
      .end()

  },
  // eslint-disable-next-line
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      // 仅在生产环境下启用该配置
      return {
        resolve: {
          alias: {
            'excel': path.resolve(__dirname, './src/excel')
          }
        },
        plugins: [
          new CompressionWebpackPlugin({
            filename: '[path].gz[query]',
            algorithm: 'gzip',
            test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
            threshold: 1024, // 只有大小大于该值的资源会被处理,当前配置为对于超过1k的数据进行处理，不足1k的可能会越压缩越大
            minRatio: 0.99, // 只有压缩率小于这个值的资源才会被处理
            deleteOriginalAssets: true // 删除原文件
          })
        ]
      }
    }
    return {
      resolve: {
        alias: {
          'vue$': 'vue/dist/vue.esm.js',
          'excel': path.resolve(__dirname, './src/excel')
        }
      }
    }
  },
  // 配置转发代理devServerProxy
  devServer: {
    disableHostCheck: true,
    port: 8888,
    proxy: devServerProxy
    // 3.5 以后不需要再配置
  }
}
